<template>
  <BackHeader :title="lang.rebate_title" />

  <div class="rebate-page app_center">
    <!-- 顶部横幅 -->
    <NuxtImg
      class="top-banner"
      src="/images/carteira/rebate_img.png"
      :alt="lang.top_image_alt"
    />

    <div class="rebate-container">
      <!-- 返利等级 -->
      <div class="rebate-levels">
        <div v-for="level in rebateLevels" :key="level.id" class="rebate-level">
          <div class="level-left">
            <NuxtImg
              src="/images/carteira/rebate_icon.png"
              :alt="lang.rebate_icon_alt"
            />
          </div>

          <div class="level-right">
            <p class="level-description">
              {{ lang.level_description_prefix }}
              <span>{{ userStore.moneyUnit }}{{ level.required }}</span>
              {{ lang.level_description_suffix }}
              <span>{{ userStore.moneyUnit }}{{ level.bonus }}</span>
            </p>

            <div class="level-bottom">
              <div class="progress-wrapper">
                <div class="progress-bar">
                  <div class="progress-outer">
                    <div
                      class="progress-inner"
                      :style="{
                        width: `${calculateProgress(
                          level.current,
                          level.required
                        )}%`,
                      }"
                    ></div>
                  </div>
                </div>
                <span class="progress-text"
                  >{{ level.current }}/{{ level.required }}</span
                >
              </div>

              <div class="deposit-btn" @click="handleDeposit(level)">
                {{ lang.deposit_button }}
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 规则说明 -->
      <div class="rules-section">
        <h3 class="rules-title">{{ lang.rules_title }}</h3>
        <p v-for="(rule, index) in lang.rules" :key="index" class="rule-item">
          {{ index + 1 }}. {{ rule }}
        </p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("rebate");
const userStore = useUserStore();

// 返利等级数据
const rebateLevels: any[] = [
  {
    id: 1,
    required: 40,
    bonus: 1,
    current: 0,
  },
  {
    id: 2,
    required: 50,
    bonus: 5,
    current: 0,
  },
  {
    id: 3,
    required: 100,
    bonus: 10,
    current: 0,
  },
  {
    id: 4,
    required: 200,
    bonus: 20,
    current: 0,
  },
  {
    id: 5,
    required: 500,
    bonus: 50,
    current: 0,
  },
];

// 计算进度百分比
const calculateProgress = (current: number, required: number): number => {
  return Math.min((current / required) * 100, 100);
};

// 处理存款
const handleDeposit = (level: any) => {
  userStore.changeShowCarteira(true);
};
</script>

<style scoped lang="scss">
.rebate-page {
  width: 100%;
  padding-top: 1.2rem;
  padding-bottom: 0.2rem;
}

.top-banner {
  width: 100%;
  margin-bottom: -0.2rem;
}

.rebate-container {
  width: 100%;
  padding: 0 0.2rem;
}

.rebate-levels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.2rem;
}

.rebate-level {
  width: 100%;
  height: 2.2rem;
  border-radius: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.4rem;
  padding: 0 0.27rem;
  background: var(--theme-color4);

  .level-left {
    width: 1.6rem;
    height: 1.6rem;
    background: var(--theme-color3);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;

    img {
      width: 0.89rem;
      height: 0.82rem;
    }
  }

  .level-right {
    width: 7rem;

    .level-description {
      font-size: 0.34rem;
      color: var(--theme-neutral1);
      margin-bottom: 0.3rem;

      span {
        color: var(--theme-dec4);
        font-size: 0.38rem;
        font-weight: 700;
      }
    }

    .level-bottom {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-column-gap: 0.5rem;

      .progress-wrapper {
        position: relative;
        width: 4.2rem;

        .progress-bar {
          .progress-outer {
            background-color: var(--theme-color3);
            border-radius: 100px;
            height: 8px;
            overflow: hidden;
            position: relative;

            .progress-inner {
              background: var(--theme-dec4);
              border-radius: 100px;
              height: 100%;
              position: absolute;
              left: 0;
              top: 0;
              transition: width 0.6s ease;
            }
          }
        }

        .progress-text {
          color: var(--theme-neutral1);
          position: absolute;
          right: 0.2rem;
          bottom: 0;
          font-size: 0.38rem;
        }
      }

      .deposit-btn {
        width: 2.4rem;
        height: 0.8rem;
        line-height: 0.8rem;
        font-size: 0.38rem;
        border-radius: 0.2rem;
        text-align: center;
        color: var(--theme-neutral1);
        background: var(--theme-dec4);
        color: var(--theme-dec3);
        cursor: pointer;
        transition: opacity 0.3s ease;

        &:hover {
          opacity: 0.8;
        }
      }
    }
  }
}

.rules-section {
  margin-top: 0.5rem;
  color: var(--theme-neutral1);
  font-size: 0.32rem;
  line-height: 0.5rem;

  .rules-title {
    color: var(--theme-dec1);
    font-size: 0.38rem;
    margin-bottom: 0.3rem;
    font-weight: 600;
  }

  .rule-item {
    margin-top: 0.2rem;
    padding-left: 0.2rem;
  }
}
</style>
